package com.xp.code.daoImpl;

import java.sql.CallableStatement;
import java.sql.Connection;

import oracle.jdbc.driver.OracleTypes;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.xp.code.dao.IDeptInfoDao;
import com.xp.code.jpa.DefaultJPADAO;
import com.xp.code.util.CommonUtils;
import com.xp.code.vo.DeptInfoVO;
import com.xp.code.vo.UserInfoVO;
/**
 * 
 * @author HAHA
 *
 */
@Repository("deptInfoDao")
public class DeptInfoDao extends DefaultJPADAO implements IDeptInfoDao {

	public DeptInfoDao() {
		
	}

	public DeptInfoVO addDeptInfos(DeptInfoVO deptInfoVO) throws Exception {
		DeptInfoVO vo=null;
		CallableStatement cs = null;
		int FLAG = 0;
		String MSG = "添加成功";
		try {
			Session session = (Session) this.getEntityManager().getDelegate();
			Connection con = session.connection();
			cs = con.prepareCall("{CALL PACKAGEXPSYS_AUTH.AddDeptInfo(?,?,?,?,?,?,?,?)}");
			cs.setString(1, CommonUtils.getUUID());
			cs.setString(2, deptInfoVO.getVarname());
			cs.setString(3, deptInfoVO.getVarcode());
			cs.setString(4, deptInfoVO.getParentid());
			cs.setString(5, deptInfoVO.getParentid());
			cs.setString(6, deptInfoVO.getRemark());
			cs.registerOutParameter(7, OracleTypes.INTEGER);
			cs.registerOutParameter(8, OracleTypes.VARCHAR);
			cs.executeUpdate();
			FLAG = cs.getInt(7);
			MSG = cs.getString(8);
			vo=new DeptInfoVO(FLAG,MSG);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cs != null) {
				cs.close();
			}
		}
		return vo;
	}
	
}
